package com.xidian.zhiancloud.service.luling.RiskIdentificationPart;

import com.xidian.zhiancloud.dao.RiskEvalAuditStatusMapper;
import com.xidian.zhiancloud.enums.GeneralResponseEnums;
import com.xidian.zhiancloud.exception.CustomizeException;
import com.xidian.zhiancloud.model.RiskEvalAuditStatus;
import com.xidian.zhiancloud.model.RiskEvalAuditStatusExample;
import org.apache.ibatis.session.RowBounds;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RiskEvalAuditStatusService {
    private RiskEvalAuditStatusMapper riskEvalAuditStatusMapper;

    public Object getList(String type, String state, String key,String riskName, int current, int size) {

        RiskEvalAuditStatusExample riskEvalAuditStatusExample = new RiskEvalAuditStatusExample();
        RiskEvalAuditStatusExample.Criteria criteria1 = riskEvalAuditStatusExample.createCriteria();
        RiskEvalAuditStatusExample.Criteria criteria2 = riskEvalAuditStatusExample.createCriteria();
        RiskEvalAuditStatusExample.Criteria criteria3 = riskEvalAuditStatusExample.createCriteria();
        criteria1.andRiskNameEqualTo(riskName);
        criteria2.andRiskNameEqualTo(riskName);
        criteria3.andRiskNameEqualTo(riskName);
        if (type != null) {
            criteria1.andTypeEqualTo(type);
            criteria2.andTypeEqualTo(type);
            criteria3.andTypeEqualTo(type);
        }
        if (state != null) {
            criteria1.andStateEqualTo(state);
            criteria2.andStateEqualTo(state);
            criteria3.andStateEqualTo(state);
        }
        if (key != null && !"".equals(key)) {
            criteria1.andStateEqualTo('%' + key + '%');
            criteria2.andTypeEqualTo('%' + key + '%');
            criteria3.andRiskNameEqualTo('%' + key + '%');
            riskEvalAuditStatusExample.or(criteria2);
            riskEvalAuditStatusExample.or(criteria3);
        }
        return riskEvalAuditStatusMapper.selectByExampleWithRowbounds(riskEvalAuditStatusExample, new RowBounds(current, size));
    }
    public List<RiskEvalAuditStatus> getById(String state) {
            RiskEvalAuditStatusExample riskEvalAuditStatusExample = new RiskEvalAuditStatusExample();
            RiskEvalAuditStatusExample.Criteria criteria = riskEvalAuditStatusExample.createCriteria();
            criteria.andStateEqualTo(state);
            List<RiskEvalAuditStatus> riskEvalAuditStatusList = riskEvalAuditStatusMapper.selectByExample(riskEvalAuditStatusExample);
            if (riskEvalAuditStatusList == null) {
                throw new CustomizeException(GeneralResponseEnums.SYSTEM_ERROR);
            }
            return riskEvalAuditStatusList;
        }
    }

